<%--
  Created by IntelliJ IDEA.
  User: 皮
  Date: 2023/5/13
  Time: 15:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>主页</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/jsp/add.jsp">
    <button>添加信息</button>
</a>
<h1>数据信息</h1>

<table border="1xp">
    <tr>
        <td>员工编号</td>
        <td>姓名</td>
        <td>性别</td>
        <td>年龄</td>
        <td>等级</td>
        <td>所在部门</td>
    </tr>
    <c:forEach var="tmp" items="${list}">
        <tr>
            <td>${tmp.id}</td>
            <td>${tmp.name}</td>
            <td>${tmp.sex}</td>
            <td>${tmp.age}</td>
            <td>${tmp.rank}</td>
            <td>${tmp.department}</td>
            <td><a href="javascript:void(0)" onclick="del(this,${tmp.id})">删除</a></td>
            <td><a href="${pageContext.request.contextPath}/person/findById/${tmp.id}">个人信息</a></td>
        </tr>
    </c:forEach>
</table>

<script src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script>

    // 处理删除
       function del(obj,id) {
        var param = confirm("你确定删除此数据?");
        if (param){
            $.ajax({
                method:"delete", // post提交
                url:"${pageContext.request.contextPath}/person/del/"+id,
                dataType:"json",
                success:function (data) {
                    if (data.status === "success"){
                        alert("删除成功");
                        $(obj).parents("tr").remove();
                    }else{
                        alert("删除失败");
                    }
                }
            })
        }
    }
</script>
</body>
</html>
